package com.zzyl.nursing.controller.member;

import com.aliyun.iot20180120.models.QueryDevicePropertyStatusRequest;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.nursing.dto.FamilyDto;
import com.zzyl.nursing.dto.QueryDeviceDataListByDayDto;
import com.zzyl.nursing.service.IDeviceService;
import com.zzyl.nursing.service.MemberUserService;
import com.zzyl.nursing.vo.MemberFamilyListByPageVo;
import com.zzyl.nursing.vo.MemberFamilyVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/member/user")
public class MemberUserController extends BaseController {

    @Autowired
    private MemberUserService memberUserService;

    @Autowired
    private IDeviceService deviceService;
    /**
     * 新增家人
     * @return
     */
    @PostMapping("/add")
    public AjaxResult addMember(@RequestBody FamilyDto familyDto) {
        memberUserService.addMember(familyDto);
        return success("操作成功");
    }

    @GetMapping("/my")
    public R<List<MemberFamilyVo>> my(){
        return R.ok(memberUserService.my());
    }

    @GetMapping("/list-by-page")
    public R<List<MemberFamilyListByPageVo>> listByPage(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                        @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        return R.ok(memberUserService.listByPage(pageNum, pageSize));
    }

    /**
     * 查询设备状态
     * @return
     */
    @PostMapping("/QueryDevicePropertyStatus")
    public AjaxResult QueryDevicePropertyStatus(@RequestBody QueryDevicePropertyStatusRequest request ){

        return deviceService.queryDevicePropertyStatus(request);
    }

    /**
     * 按天统计查询指标数据
     * @return
     */
    @GetMapping("/queryDeviceDataListByDay")
    public AjaxResult queryDeviceDataListByDay(QueryDeviceDataListByDayDto request ){

        return memberUserService.queryDeviceDataListByDay(request);
    }

    /**
     * 按周统计查询指标数据
     * @param request
     * @return
     */
    @GetMapping("/queryDeviceDataListByWeek")
    public AjaxResult queryDeviceDataListByWeek(QueryDeviceDataListByDayDto request ){
        return memberUserService.queryDeviceDataListByWeek(request);
    }
}
